<?php
	/**
	* Products Brand Delete
	* 
	* @author trungdt
	* @since Sep 27, 2011
	*/
	if (!defined('EXPONENT')) exit('');

	$band = null;
	if (isset($_POST['id'])) {
		$band = $db->selectObject('productsmodule_brand','id='.intval($_POST['id']));
		if ($band) {
			$loc = unserialize($band->location_data);
		}
	}

	$obj=null;
	$obj->success=1;
	if ($band) {
		if (exponent_permissions_check(array('administrate',"configure"),$loc)) {
			// remove all product belong to this brand
			$db->delete('productsmodule_products',' brand_id = '.$band->id);
			// remove brand
			$db->delete('productsmodule_brand','id='.$band->id);
			$obj->id=$band->id;
		} else {
			//echo SITE_403_HTML;
			$obj->success=0;
		}
	} else {
		//echo SITE_404_HTML;
		$obj->success=0;
	}

	echo json_encode($obj);
?>
